﻿//------------------------------------------------------------------------------------------------- 
// <copyright file="ImagePanel.cs" company="Elpaulo Productions">
//   Copyright (c) Elpaulo Productions. All rights reserved.
// </copyright>
//-------------------------------------------------------------------------------------------------
namespace Elpaulo.Canardpc.CanardpcImageUploader
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
using Elpaulo.Canardpc.TofCanardpcAPI;
   
    /// <summary>
    /// Notify that the ImagePanel is deleted
    /// </summary>
    /// <param name="sender">Sender of the event</param>
    /// <param name="e">Event args</param>
    public delegate void DeletedItem(object sender, EventArgs e);

    /// <summary>
    /// Panel for image to upload
    /// </summary>
    public partial class ImagePanel : UserControl
    {
        /// <summary>
        /// Local path of the image to upload
        /// </summary>
        private string _localpath;

        /// <summary>
        /// URL of webpage that contains all links when image is uploaded
        /// </summary>
        private string _linkPage;

        /// <summary>
        /// State of this image
        /// </summary>
        private ImageState _imageState;

        /// <summary>
        /// Initializes a new instance of the ImagePanel class
        /// </summary>
        /// <param name="localpath">Local path of the image</param>
        public ImagePanel(string localpath)
        {
            InitializeComponent();
            LocalPath = localpath;
        }

        /// <summary>
        /// Sended when this ImagePanel is deleted
        /// </summary>
        public event DeletedItem Deleted;

        /// <summary>
        /// Accessor for this image state
        /// </summary>
        public ImageState ImageState
        {
            get
            {
                return _imageState;
            }

            set
            {
                _imageState = value;

                switch (_imageState)
                {
                    case ImageState.NotUploaded:
                        btnGoToLinkPage.Enabled = false;
                        break;
                    case ImageState.Queued:
                        btnGoToLinkPage.Enabled = false;
                        ptbState.Image = Properties.Resources.Queued;
                        break;
                    case ImageState.Uploading:
                        btnGoToLinkPage.Enabled = false;
                        ptbState.Image = Properties.Resources.Loading;
                        break;
                    case ImageState.Uploaded:
                        btnGoToLinkPage.Enabled = true;
                        ptbState.Image = Properties.Resources.Validate;
                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// Accessor for the link page
        /// </summary>
        public string LinkPage
        {
            get
            {
                return _linkPage;
            }

            set
            {
                _linkPage = value;
                txtLinkPage.Text = _linkPage;
            }
        }

        /// <summary>
        /// Accessor for localpath. set method will fill localpath textbox and the associated picturebox
        /// </summary>
        public string LocalPath
        {
            get
            {
                return _localpath;
            }

            set
            {
                _localpath = value;
                txtLocalPath.Text = _localpath;
                ptbImage.Load(_localpath);
            }
        }

        /// <summary>
        /// Send the Deleted event to notify that this ImagePanel must be deleted by the General form
        /// </summary>
        /// <param name="sender">The remove button</param>
        /// <param name="e">Event args</param>
        private void BtnRemove_Click(object sender, EventArgs e)
        {
            Deleted(this, e);
        }

        /// <summary>
        /// Click event on the open link page button
        /// </summary>
        /// <param name="sender">The open link page button</param>
        /// <param name="e">Event args</param>
        private void BtnGoToLinkPage_Click(object sender, EventArgs e)
        {
            Process.Start(txtLinkPage.Text);
        }

        public void FillLinkTextBoxes(ImageLinks imageLinks)
        {
            txtDirectLink.Text = imageLinks.DirectLink;
            txtFullSizeBBCode.Text = imageLinks.BBCodeFullSize;
            LinkPage = imageLinks.LinkPage;
            txtVignettte200BBCode.Text = imageLinks.BBCode200;
            txtVignettte600BBCode.Text = imageLinks.BBCode600;
        }
    }
}
